package com.zhengtoudai.ui.presenter;

import com.zhengtoudai.http.HttpApi;
import com.zhengtoudai.ui.bean.Result;
import com.zhengtoudai.ui.bean.TenderRecord;
import com.zhengtoudai.ui.view.CommonView;

import javax.inject.Inject;

import rx.Observer;
import rx.functions.Action0;

/**
 * Created by Administrator on 2016/9/5 0005.
 */

public class TenderRecordPresenterImpl extends BasePresenterImpl<CommonView<TenderRecord>> implements TenderRecordPresenter{

    @Inject
    public TenderRecordPresenterImpl(){

    }
    @Override
    public void tenderRecord(String borrowId) {
        mSubscription=HttpApi.getInstance().tenderRecord(borrowId)
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {
                        mView.showDialog();
                    }
                }).subscribe(new Observer<Result<TenderRecord>>() {
            @Override
            public void onCompleted() {
                mView.dismissDialog();
            }

            @Override
            public void onError(Throwable e) {
                mView.onFailure(e);
                mView.dismissDialog();
            }

            @Override
            public void onNext(Result<TenderRecord> tenderRecordResult) {
                mView.onResult(tenderRecordResult);
            }
        });
    }

    @Override
    public void offerToBuyRecord(String transferEId) {
        mSubscription=HttpApi.getInstance().offerToBuyRecord(transferEId)
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {
                        mView.showDialog();
                    }
                }).subscribe(new Observer<Result<TenderRecord>>() {
                    @Override
                    public void onCompleted() {
                        mView.dismissDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.onFailure(e);
                        mView.dismissDialog();
                    }

                    @Override
                    public void onNext(Result<TenderRecord> tenderRecordResult) {
                        mView.onResult(tenderRecordResult);
                    }
                });
    }
}
